package com.dmz.etc.server.utils.ftp;

import cn.hutool.extra.ftp.Ftp;
import com.dmz.common.utils.secure.GMUtil;
import com.dmz.etc.server.config.EnvConfig;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lee
 */
@Slf4j
public class FtpClient {

    public Ftp etcFtp() {
        String key = EnvConfig.getProperty("sm4.key");
        String iv = EnvConfig.getProperty("sm4.iv");
        String host = EnvConfig.getProperty("dmz.ftp.etc.host");
        int port = Integer.valueOf(EnvConfig.getProperty("dmz.ftp.etc.port"));
        String usernameEb = EnvConfig.getProperty("dmz.ftp.etc.username");
        String passwordEb = EnvConfig.getProperty("dmz.ftp.etc.password");
        log.info("key:{}", key);
        log.info("iv:{}", iv);
        log.info("usernameEb:{}", usernameEb);
        log.info("passwordEb:{}", passwordEb);
        String username = GMUtil.db(key, iv, usernameEb);
        String password = GMUtil.db(key, iv, passwordEb);
        log.info("username:{}", username);
        log.info("password:{}", password);
        return new Ftp(host, port, username, password);
    }

    public Ftp bankFtp() {
        String key = EnvConfig.getProperty("sm4.key");
        String iv = EnvConfig.getProperty("sm4.iv");
        String host = EnvConfig.getProperty("dmz.ftp.bank.host");
        int port = Integer.valueOf(EnvConfig.getProperty("dmz.ftp.bank.port"));
        log.info("key:{}", key);
        log.info("iv:{}", iv);
        String usernameEb = EnvConfig.getProperty("dmz.ftp.bank.username");
        String passwordEb = EnvConfig.getProperty("dmz.ftp.bank.password");
        log.info("usernameEb:{}", usernameEb);
        log.info("passwordEb:{}", passwordEb);
        String username = GMUtil.db(key, iv, usernameEb);
        String password = GMUtil.db(key, iv, passwordEb);
        log.info("username:{}", username);
        log.info("password:{}", password);
        return new Ftp(host, port, username, password);
    }
}
